# 
import argparse
from typing import Dict
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

class Chp01Sec04S2(object):
    def __init__(self):
        self.name = ''

    @staticmethod
    def startup(params:Dict = {}) -> None:
        print(f'Linear Regression 2 Demo v0.0.1')
        plt.rcParams['figure.figsize'] = [8, 8]
        plt.rcParams.update({'font.size': 18})

        # Load dataset
        A = np.loadtxt('study/ddse/supports/DATA_PYTHON\DATA/hald_ingredients.csv',delimiter=',')
        b = np.loadtxt('study/ddse/supports/DATA_PYTHON/DATA/hald_heat.csv',delimiter=',')

        # Solve Ax=b using SVD
        U, S, VT = np.linalg.svd(A,full_matrices=0)
        x = VT.T @ np.linalg.inv(np.diag(S)) @ U.T @ b

        plt.plot(b, color='k', linewidth=2, label='Heat Data') # True relationship
        plt.plot(A@x, '-o', color='r', linewidth=1.5, markersize=6, label='Regression')
        plt.legend()
        plt.show()

def main(params:Dict = {}) -> None:
    Chp01Sec04S2.startup(params=params)

def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--run_mode', action='store',
        type=int, default=1, dest='run_mode',
        help='run mode'
    )
    return parser.parse_args()

if '__main__' == __name__:
    args = parse_args()
    params = vars(args)
    main(params=params)